const { initHeadlessPluginWin } = require('../../../core/pluginRunService/initHeadlessPluginWin')
const { onEmit } = require('../../baseService/broadService/processor/broadcastProcessor');
const { asyncTopicConstants } = require('../../../common/constans/asyncTopicContans')
const { hideMain } = require('../../winService/baseWinService/hideMain');
const EnvContext = require('../../../common/context/EnvContext');

exports.doRunHeadlessPlugin = function (request) {
    hideMain()
    initHeadlessPluginWin(request.plugin.cmdInfo.pluginInfo, () => {
        broadcastFeatureCode(request)
    })
}

function broadcastFeatureCode(request) {
    const pluginId = request.plugin.cmdInfo.pluginInfo.pluginId
    const theWin = EnvContext.getInstance().getBrowserWindow(pluginId)
    onEmit(asyncTopicConstants.onTrigger, request, theWin)
}